﻿using log4net;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace LogCentre
{
    public class AuxLog
    {
        private static readonly ILog logger = LogManager.GetLogger("auxLogger");

        static AuxLog()
        {
            //var path = @"C:\PGL\Config\log4net_config.xml";
            var path = AppDomain.CurrentDomain.BaseDirectory + @"Config\log4net_config.xml";

            //string path = new DirectoryInfo(string.Format(@"{0}..\Config\log4net_config.xml", AppDomain.CurrentDomain.BaseDirectory)).FullName;

            log4net.Config.XmlConfigurator.Configure(new FileInfo(path));

            //log4net.Config.XmlConfigurator.Configure();
        }

        public static void Debug(string msg)
        {
            logger.Debug(msg);
        }

        public static void Error(string msg)
        {
            //while (!logger.IsErrorEnabled)
            //{
            //    Task.Delay(1);
            //}
            logger.Error(msg);

            //if (outMsg != msg)
            //{
            //    StackTrace stackTrace = new StackTrace();
            //    StackFrame stackFrame = stackTrace.GetFrame(1);
            //    MethodBase methodBase = stackFrame.GetMethod();
            //    lErr.Error("类名:" + methodBase.ReflectedType.FullName + " 方法名:" + methodBase.Name + " 信息:" + msg);
            //    if (msg.Contains("System.OutOfMemoryException"))
            //    {
            //        UiLogReceived(msg, MessageType.ERROR);
            //        //UiLogReceived(null, new UiLogEventArgs(msg));
            //    }
            //    outMsg = msg;
            //}
        }
    }
}
